<template>
    <div class="show_table">
        <el-form
            ref="testdata"
            :model="formdata"
            class="form">
            <el-form-item label="选择对抗样本数据集">
                <!-- {{formdata.adv_path}}
                {{formdata.post_path}} -->
                <el-select v-model="formdata.post_path" aria-placeholder="请选择对抗样本数据集">
                    <el-option v-for="(item,index) in formdata.adv_path" :key="index" :label="item.show_path" :value="item.gen_path">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitFormdata()">提交</el-button>
                <el-button type="danger"  @click="resetFormdata()">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import axios from 'axios'
/* eslint-disable */
    import { isInSessionStorage } from '../../assets/js/utils'
    export default{
        name:'ReadForTest',
        data(){
            return {
                formdata:{
                    adv_path:[],
                    post_path:''
                }
            }
        },
        mounted(){
            let allData = []
            let keylist = ['DeepFool','FSGM','PGD','CW','SimBA','BA','FGSM','SIMBA']
            keylist.forEach((key,index)=>{
                let items
                if(isInSessionStorage(key)){
                    items = JSON.parse(sessionStorage.getItem(key))
                    items.forEach((gen_js,index)=>{
                        let data = JSON.parse(gen_js)
                        let segments = data.gen_path.split('/')
                        console.log(segments)
                        allData.push({
                            gen_path: data.gen_path,
                            show_path: segments[segments.length - 1]
                        })
                    })
                }
            })
            this.formdata.adv_path = allData
        },
        methods:{
            submitFormdata(){
                axios.post('/api/testpage/test',{
                    path:this.formdata.post_path
                }).then(
                    res=>{
                        //触发全局事件总线，交给其他组件处理
                        this.$bus.$emit('test_pass',res.data)
                    }
                )
            },
            resetFormdata(){
                this.formdata.post_path = ''
            }
        }
    }

</script>
<style scoped>
 @import url('../../assets/css/wbt_form.css');
</style>
